alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']

def en_decode(d, t, s):
    abc = alphabet
    if d == "decode":
       abc.reverse()
    output = ""
    for letter in t:
        if  letter not in abc:
            output += letter
        else:
            index = abc.index(letter) + s
            if index >= len(abc):
                index = index % len(abc)
            output += abc[index]
    print(output)


while True:
    direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
    if direction != "encode" and direction != "decode":
        print("Go away! You are idiot")

    text = input("Type your message:\n").lower()
    shift = int(input("Type the shift number:\n"))
    en_decode(direction, text, shift)
    is_continue = input("Type 'y' if you want another encription. Or 'n' if not:\n").lower()
    if is_continue != "y":
        break
#TODO-1: Create a function called 'encrypt' that takes the 'text' and 'shift' as inputs.

    #TODO-2: Inside the 'encrypt' function, shift each letter of the 'text' forwards in the alphabet by the shift amount and print the encrypted text.  
    #e.g. 
    #plain_text = "hello"
    #shift = 5
    #cipher_text = "mjqqt"
    #print output: "The encoded text is mjqqt"

    ##HINT: How do you get the index of an item in a list:
    #https://stackoverflow.com/questions/176918/finding-the-index-of-an-item-in-a-list

    ##🐛Bug alert: What happens if you try to encode the word 'civilization'?🐛

#TODO-3: Call the encrypt function and pass in the user inputs. You should be able to test the code and encrypt a message. 
